<?php
declare (strict_types = 1);

namespace app\command;

use app\beautiful\model\order\GoodsOrderItemModel;
use app\beautiful\model\order\OrderGoodsModel;
use app\stores\model\order\GoodsOrderModel;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;

class OrderStatus extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('orderstatus')
            ->setDescription('the orderstatus command');
    }

    protected function execute(Input $input, Output $output)
    {
        $set_meal_order_ids = GoodsOrderItemModel::where(['type'=>3])->column('order_id');
        $order_list = GoodsOrderModel::whereIn('order_id',$set_meal_order_ids)->where(['is_delete'=>0,'is_paid'=>1,'status'=>10])->select()->toArray();
        $up['status']='13';
        $update_order_ids=[];
        $order = GoodsOrderModel::where('1=1')->find();
        foreach ($order_list as $k=>$v){
            $item = GoodsOrderItemModel::where(['order_id'=>$v['order_id']])->find();
            if($v['order_type']=='pin_tuan'){
                $where_g = [
                    ['is_delete','=',0],
                    ['pin_tuan_order_id','=',$v['pin_tuan_order_id']]
                ];

            }else{
                $where_g = [
                    ['is_delete','=',0],
                    ['order_id','=',$v['order_id']],
                    ['order_item_id','=',$item->order_item_id]
                ];
            }
            $goods = OrderGoodsModel::where($where_g)->json(['use_limit_detail'],true)->find();
            //到期时间
            $order->pay_time = strtotime($v['pay_time']);
            $return = goodsEndTime($goods,$order);
            if($return['is_effect']<1){
                $update_order_ids[]=$v['order_id'];
                GoodsOrderModel::update($up,['order_id'=>$v['order_id']]);
            }
        }
        $str = $update_order_ids?implode(',',$update_order_ids):'';
        // 指令输出
        $output->writeln($str);
    }
}
